// 验证规则
$('#m-vip_rgt').validate({
    rules: {
        ID: {
            required: true,
            password: true
        },
        TJ_ID: {
            required: true,
            password: true
        },
        JD_ID: {
            required: true,
            password: true
        },
        choose_vip: {
            required: true,
            select: true
        },
        password: {
            required: true,
            password: true
        },
        QR_password: {
            required: true,
            equalTo: '#password'
        },
        name: {
            required: true,
            maxlength: 5
        },
        tel: {
            required: true,
            telNum: true
        },
        email: {
            required: true,
            email: true
        },
        checkbox: {
            required: true
        }
    },
    messages: {
        ID: {
            required: "不能为空"
        },
        TJ_ID: {
            required: "不能为空"
        },
        JD_ID: {
            required: "不能为空"
        },
        choose_vip: {
            required: "不能为空"
        },
        password: {
            required: "不能为空"
        },
        QR_password: {
            required: "不能为空",
            equalTo: "两次输入密码不一致"
        },
        name: {
            required: "不能为空"
        },
        tel: {
            required: "不能为空"
        },
        email: {
            required: "不能为空"
        },
        checkbox: {
            required: "请阅读并同意此协议"
        }
    },
    errorPlacement: function (error, element) {
        $(element).siblings('.u-ts').html(error)
    },
    errorElement: 'span',
    submitHandler: function (form) {
        form.submit();
    }
});

jQuery.validator.addMethod('telNum', function (value, element) {
    var phoneNum = /^[1][34578][\d]{9}$/.test(value);
    return this.optional(element) || phoneNum
}, '请输入正确手机号');

jQuery.validator.addMethod('password', function (value, element) {
    var password = /^[a-z0-9_-]{6,18}$/.test(value);
    return this.optional(element) || password
}, '请输入6-18位字母，数字_-');

jQuery.validator.addMethod('select', function (value, element) {
    return this.optional(element) || (value !== '0')
}, '请选择要注册的会员等级');
